package com.weiyin.examination.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.weiyin.examination.R;
import com.weiyin.examination.application.Constant;
import com.weiyin.examination.listener.DialogResultInterface;
import com.weiyin.examination.util.LayoutHelper;

import java.util.Map;

/**
 * @author njf
 * @date 2017/11/23
 */

public class SubmitDialog extends Dialog implements View.OnClickListener {
    private Activity activity;
    private Button submitNo, submitYes;
    private TextView submitContent, submitTextView;
    private int submitYesIndex = 0, position;
    private DialogResultInterface dialogResultInterface;

    public void setDialogResultInterface(DialogResultInterface dialogResultInterface) {
        this.dialogResultInterface = dialogResultInterface;
    }

    public SubmitDialog(@NonNull Activity context) {
        super(context);
        this.activity = context;
    }

    public SubmitDialog(@NonNull Activity context, @StyleRes int themeResId, int position) {
        super(context, themeResId);
        this.activity = context;
        this.position = position;
    }

    protected SubmitDialog(@NonNull Activity context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.activity = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.submit_dialog_layout);
        LayoutHelper layoutHelper = new LayoutHelper(activity);
        layoutHelper.scaleView(findViewById(R.id.submitDialogLayout));

        initView();
    }

    private void initView() {
        submitYesIndex = 0;


        submitTextView = (TextView) findViewById(R.id.submitTextView);
        submitContent = (TextView) findViewById(R.id.submitContent);
        submitYes = (Button) findViewById(R.id.submitYes);
        submitNo = (Button) findViewById(R.id.submitNo);

        submitYes.setOnClickListener(this);
        submitNo.setOnClickListener(this);

        submitTextView.setText("还有"+position+"题未完成");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.submitYes:
                if (submitYesIndex == 0) {
                    submitYesIndex++;
                    submitYes.setText(activity.getResources().getString(R.string.submit_yes1));
                    submitNo.setText(activity.getResources().getString(R.string.submit_no1));
                    submitContent.setText(activity.getResources().getString(R.string.submit_content1));
                } else {
                    dialogResultInterface.result(Constant.YES, "","");
                    dismiss();
                }
                break;
            case R.id.submitNo:
                dismiss();
                break;
            default:
                break;
        }
    }
}
